import Vue from 'vue'
import VueRouter from 'vue-router'
import routers from './router'
import store from '../store/index'

Vue.use(VueRouter)

const routes = routers;

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  store.commit('updateLoadingStatus', {showLoading: true});
  next();
});
// 路由跳转后的钩子
router.afterEach(to => {
  store.commit('updateLoadingStatus', {showLoading: false})
});

export default router
